<?php

namespace MyBlog\Models;

use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
    protected $guarded = array('id');

    public function articles() {
        return $this->hasMany('MyBlog\Models\Article');
    }

    public function galleries() {
        return $this->hasMany('MyBlog\Models\Gallery');
    }

    public function getState() {
        $state = '正常';
        if($this->disabled) {
            $state = '禁用';
        }
        return $state;
    }
    
    const TYPE_ARTICLES = 'articles';
    const TYPE_GALLERIES = 'galleries';
//     const TYPE_TEXT = 'text';
    
    public static $types = array(
    	self::TYPE_ARTICLES,
    	self::TYPE_GALLERIES,
//     	self::TYPE_TEXT,
    );
    
    public static $TYPE_EX = array(
    	self::TYPE_ARTICLES => '文章列表',
    	self::TYPE_GALLERIES => '相册列表',
//     	self::TYPE_TEXT => '文本显示',
    );
    
    public function type_ex() {
    	return self::$TYPE_EX[$this->type];
    }

    public static $rules = [
        'type' => 'required',
        'name' => 'required',
    ];

    public static $msgs = [
        'type.required' => '分类类型不能为空。',
        'name.required' => '分类名称不能为空。',
    ];
}
